package com.itboye.textileexpres.logincontroller;

import java.util.Observable;
import java.util.Observer;

import android.app.Activity;

import com.itboye.textileexpres.base.MainApplication;
import com.itboye.textileexpres.util.DebugLog;
import com.itboye.textileexpres.util.IsMobileNumPhone;
import com.itboye.textileexpres.util.SPUtils;
import com.umeng.message.PushAgent;
import com.umeng.message.UTrack.ICallBack;

/**
 * 登录相关控制类--状态模式</br></br>
 * 
 * 登录成功后调用setLoginState(new LoginedState());</br></br> 退出登录后调用setLoginState(new
 * UnLoginState());</br></br> 进入主Activity前一定要设置一次，要么登录要么未登录</br></br>
 * 
 * @author Young
 * 
 */
public class LoginController implements Observer {

	// static UserPresenter userPresenter;
	private static ILoginState loginState = new UnLoginState();
	private static String registrationId;
	private static PushAgent mPushAgent;

	public static void setLoginState(ILoginState loginState) {

		LoginController.loginState = loginState;
		if (loginState instanceof UnLoginState) {
			DebugLog.v("bytag", "未登录。。。");
		} else if (loginState instanceof LoginedState) {

			mPushAgent = PushAgent.getInstance(MainApplication.context);
			mPushAgent.onAppStart();
			String uid = (String) SPUtils.get(MainApplication.context, null,
					IsMobileNumPhone.isUid(), "");
			mPushAgent.addExclusiveAlias(uid, "ihome", new ICallBack() {

				@Override
				public void onMessage(boolean arg0, String arg1) {
					// TODO Auto-generated method stub
					System.out.println(arg0 + "arg222" + arg1);
				}
			});

		}
	}

	public static void SetString(Activity act, Object data) {
		loginState.SetString(act, data);
	}

	@Override
	public void update(Observable observable, Object data) {
		// TODO Auto-generated method stub

	}
}
